package com.ssh.tts.service;

import java.util.List;

import com.ssh.tts.dao.IouDao;
import com.ssh.tts.model.Iou;

public class IouService {
	
	private IouDao id = new IouDao();
	
	/**
	 * 购票
	 * @param iou
	 * @return
	 */
	public void addIou(Iou iou) {
		int result = id.addIou(iou);
		if (result < 0) {
			throw new RuntimeException("购票失败!");
		}
	}
	
	/**
	 * 退票是根据user_id查询
	 * @param user_id
	 * @return
	 */
	public List<Iou> queryByUser_id(Integer user_id) {
		List<Iou> list = id.queryByUser_id(user_id);
		if (list.size() <= 0) {
			throw new RuntimeException("没有行程!");
		}
		return list;
	}
	
	/**
	 * 退票
	 * @param iou
	 * @return
	 */
	public void deleteIou(Iou iou) {
		int result = id.deleteIou(iou);
		if (result < 0) {
			throw new RuntimeException("退票失败!");
		}
	}
}
